package topSort;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * 
 * @author benny
 * 
 */
public class AdjacencyList extends AdjacencyStructure {

	protected AdjacencyList(Graph g) {
		super(g);

	}

	@Override
	public void print() {
		super.print();

		for (int i = 1; i < _g.getList().length - 1; i++) {

			int c = 0;

			for (int j = 0; j < _g.getList()[i - 1].size(); j++) {

				c++;
				if (c <= 1) {
					System.out.println(_g.getList()[i - 1].getFirst()
							.getStart().get_name()
							+ "\t-> ["
							+ _g.getList()[i - 1].get(j).getEnd().get_name()
							+ ", "
							+ _g.getList()[i - 1].get(j).getValue()
							+ "]");
				} else {
					System.out.println("\t   ["
							+ _g.getList()[i - 1].get(j).getEnd().get_name()
							+ ", " + _g.getList()[i - 1].get(j).getValue()
							+ "]");

				}

			}
			c = 0;
		}
		System.out.println();

	}

	@Override
	public ArrayList<Vertice> getNeighbours(int key) {

		LinkedList<Edge> temp = _g.getList()[key - 1];
		ArrayList<Vertice> nodes = new ArrayList();
		Iterator<Edge> it = temp.listIterator();
		while (it.hasNext()) {
			Edge e = it.next();
			nodes.add(e.getEnd());
		}
		return nodes;
	}

}